﻿using VideoStore.Domain.Entities;
using System.Linq;

namespace VideoStore.Domain.DAL
{
    public interface IStoreDataAccess
    {
        /// <summary>
        /// Gets the store by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        Store GetStoreById(int id);

        /// <summary>
        /// Creates the store.
        /// </summary>
        /// <param name="newStore">The new store.</param>
        /// <returns></returns>
        Store CreateStore(Store newStore);
    }

    public class StoreDataAccess : BaseDataAccess, IStoreDataAccess
    {
        #region Implementation of IStoreDataAccess

        /// <summary>
        /// Gets the store by id.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <returns></returns>
        public Store GetStoreById(int id)
        {
            Store store = DataContext.Stores.SingleOrDefault(c => c.id == id);
            return store;
        }

        /// <summary>
        /// Creates the store.
        /// </summary>
        /// <param name="newStore">The new store.</param>
        /// <returns></returns>
        public Store CreateStore(Store newStore)
        {
            DataContext.Stores.InsertOnSubmit(newStore);
            DataContext.SubmitChanges();
            return newStore;
        }

        #endregion
    }
}
